#include"../mqserver/mq_queue.hpp"
#include<gtest/gtest.h>

MsgqueueManager::ptr mqmp;
class Queuetest:public testing::Environment{
public:
    virtual void SetUp()override
    {
        mqmp=std::make_shared<MsgqueueManager>("./data/meta.db");
    }
    virtual void TearDown()override
    {
        mqmp->clear();
    }
};

// TEST(queue_test,insert_test)
// {
//     std::unordered_map<std::string,std::string> map={{"k1","v1"}};
//     mqmp->declareQueue("queue1",true,false,false,map);
//     mqmp->declareQueue("queue2",true,false,false,map);
//     mqmp->declareQueue("queue3",true,false,false,map);
//     mqmp->declareQueue("queue4",true,false,false,map);

//     ASSERT_EQ(mqmp->size(),4);
// }

TEST(queue_test,select_test)
{
    ASSERT_EQ(mqmp->exists("queue1"),false);
    ASSERT_EQ(mqmp->exists("queue2"),true);
    ASSERT_EQ(mqmp->exists("queue3"),true);
    ASSERT_EQ(mqmp->exists("queue4"),true);
    MessageQueue::ptr q=mqmp->selectQueue("queue2");
    
    ASSERT_EQ(q->_name,"queue2");
    ASSERT_EQ(q->_durable,true);
    ASSERT_EQ(q->_exclusive,false);
    ASSERT_EQ(q->_auto_delete,false);
    ASSERT_EQ(q->getArgs(),std::string("k1=v1&"));

}

TEST(queue_test,remove_test)
{
    mqmp->remove("queue2");
    ASSERT_EQ(mqmp->exists("queue2"),false);
}



int main(int argc,char*argv[])
{
    testing::InitGoogleTest(&argc,argv);
    testing::AddGlobalTestEnvironment(new Queuetest);
    RUN_ALL_TESTS();
}